import 'package:flutter_module/common/base/logic/BasicLogic.dart';
import '../../common/http/ApiConstant.dart';
import '../../common/http/YZHttpUtils.dart';
import '../../common/third/analytics/YZAnalytics.dart';
/// @description:
/// @author
/// @date: 2023-12-07 09:19:46
class AccountSettingLogic extends BasicLogic {
  /// 微信昵称
  String weChatNickName = "未绑定";

  /// 昵称回调
  Function(String weChatNickName)? onDataReceived;

  @override
  void onInit() {
    // TODO: implement onInit
    super.onInit();

    getIsItBoundToWeChat();
  }

  /// 请求是否绑定了微信
  void getIsItBoundToWeChat() {
    // weChatNickName = "测试微信名字";
    // onDataReceived?.call(weChatNickName);
    HttpUtils.get(api_sys_isItBoundToWeChat, successCallBack: (data, total) {
      if (data['nickName'] != null) {
        weChatNickName = data['nickName'];
        onDataReceived?.call(weChatNickName);
      }
    }, errorCallBack: (e) {});
  }

  /// 解除绑定微信
  void requestWechatUnbinding() {
    // 清除微信信息，重置页面
    // weChatNickName = "";
    // onDataReceived?.call(weChatNickName);
    HttpUtils.get(api_sys_wechatUnbinding, successCallBack: (data, total) {
      YZAnalytics.track("W0029", "微信解绑点击", "", null);
      // 清除微信信息，重置页面
      weChatNickName = "未绑定";
      onDataReceived?.call(weChatNickName);
    }, errorCallBack: (e) {});
  }
}
